<%@ page import="util.CookieUtil" %>
<%@ page import="entity.User" %><%--
  Created by IntelliJ IDEA.
  User: 石小俊
  Date: 2024/11/9
  Time: 15:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>主页</title>
</head>
<body>
<%--<h1>欢迎您:<%=CookieUtil.findByName("username", request)%></h1>--%>
<!--
    当用户未登录时,展示登录与注册的链接
-->
<%
    // 判断session中是否保存user
    User user = (User) session.getAttribute("user");
    // 如果user值为null,说明session中没有保存用户信息,即:用户未登录
    if(user == null){
%>
<a href="<%=request.getContextPath()%>/jsp/login.jsp">登录</a>
<a href="">注册</a>
<%
    } else{
%>
<!--
    当用户登录之后展示欢迎与注销
-->
欢迎您:<%=user.getUsername()%>
<a href="<%=request.getContextPath()%>/logout">注销</a>
<%
    }
%>
</body>
</html>
